/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.customer.exercises.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.customer.exercises.entity.TcustomerExercises;
import com.jeesite.modules.zx.customer.exercises.service.TcustomerExercisesService;

/**
 * 客户练习表Controller
 * @author zpp
 * @version 2020-01-30
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/customer/exercises/tcustomerExercises")
public class TcustomerExercisesController extends BaseController {

	@Autowired
	private TcustomerExercisesService tcustomerExercisesService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TcustomerExercises get(String id, boolean isNewRecord) {
		return tcustomerExercisesService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:customer:exercises:view")
	@RequestMapping(value = {"list", ""})
	public String list(TcustomerExercises tcustomerExercises, Model model) {
		model.addAttribute("tcustomerExercises", tcustomerExercises);
		return "modules/zx/customer/exercises/tcustomerExercisesList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:customer:exercises:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TcustomerExercises> listData(TcustomerExercises tcustomerExercises, HttpServletRequest request, HttpServletResponse response) {
		tcustomerExercises.setPage(new Page<>(request, response));
		Page<TcustomerExercises> page = tcustomerExercisesService.findPage(tcustomerExercises);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:customer:exercises:view")
	@RequestMapping(value = "form")
	public String form(TcustomerExercises tcustomerExercises, Model model) {
		model.addAttribute("tcustomerExercises", tcustomerExercises);
		return "modules/zx/customer/exercises/tcustomerExercisesForm";
	}

	/**
	 * 保存客户练习表
	 */
	@RequiresPermissions("zx:customer:exercises:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TcustomerExercises tcustomerExercises) {
		tcustomerExercisesService.save(tcustomerExercises);
		return renderResult(Global.TRUE, text("保存客户练习表成功！"));
	}
	
	/**
	 * 停用客户练习表
	 */
	@RequiresPermissions("zx:customer:exercises:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TcustomerExercises tcustomerExercises) {
		tcustomerExercises.setStatus(TcustomerExercises.STATUS_DISABLE);
		tcustomerExercisesService.updateStatus(tcustomerExercises);
		return renderResult(Global.TRUE, text("停用客户练习表成功"));
	}
	
	/**
	 * 启用客户练习表
	 */
	@RequiresPermissions("zx:customer:exercises:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TcustomerExercises tcustomerExercises) {
		tcustomerExercises.setStatus(TcustomerExercises.STATUS_NORMAL);
		tcustomerExercisesService.updateStatus(tcustomerExercises);
		return renderResult(Global.TRUE, text("启用客户练习表成功"));
	}
	
	/**
	 * 删除客户练习表
	 */
	@RequiresPermissions("zx:customer:exercises:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TcustomerExercises tcustomerExercises) {
		tcustomerExercisesService.delete(tcustomerExercises);
		return renderResult(Global.TRUE, text("删除客户练习表成功！"));
	}
	
}